package procilege.impl.formatter;

import java.util.Iterator;

import procilege.compute.ExprFormatTraveller;
import procilege.compute.PlaceTypeMetadata;
import procilege.compute.PlaceType;
import procilege.lang.PredicateExpr;
import procilege.lang.PredicateFunction;

@PlaceTypeMetadata(type = PredicateFunction.class)
public class PredicateFunctionFormatter implements PlaceType<ExprFormatTraveller> {

	public void visit(ExprFormatTraveller tr, Object place) {

		StringBuilder sb = tr.getBuilder();
		PredicateFunction n = (PredicateFunction) place;

		tr.setout(n.getName());

		if (!n.getArgs().isEmpty()) {
			sb.append("(");
			Iterator<PredicateExpr> itr = n.getArgs().iterator();
			tr.setout(itr.next());

			while (itr.hasNext()) {
				sb.append(",");
				tr.setout(itr.next());
			}
			sb.append(")");
		}
	}
}